/**
 * 部门管理初始化
 */
var Reservations = {
    id: "ReservationsTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Reservations.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '预约号', field: 'reservationsNum', align: 'center', valign: 'middle', sortable: true},
        {title: '客户姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true},
        {title: '状态', field: 'status', align: 'center', valign: 'middle', sortable: true},
        {title: '状态2', field: 'statuss', align: 'center', valign: 'middle', sortable: true},
        {title: '预约门诊', field: 'outpatientName', align: 'center', valign: 'middle', sortable: true},
        {title: '预约到店时间', field: 'appointmentArrivalTime', align: 'center', valign: 'middle', sortable: true},
        {title: '回访时间', field: 'appointmentTime', align: 'center', valign: 'middle', sortable: true},
        {
            title: '回访操作', field: 'RevisitRecord', align: 'center', valign: 'middle', sortable: true, width: '6%',
            formatter: function (value, row, index) {
                if (row.oneChannel != '直接上门' && row.oneChannel != '老带新') {
                    return "<span onmouseout='Reservations.suspensionOut()' onmouseover='Reservations.suspensionOver(" + '"' + row.id + '"' + ")' onclick='Reservations.revisitOperation(" + '"' + row.id + '"' + ")'>[预约回访]</span>"
                } else {
                    return "";
                }
            }
        },
        {title: '回访', field: 'huifang', visible: false, align: 'center', valign: 'middle', sortable: true},
        {
            title: '性别', field: 'customerSex', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "男";
                } else if (value == 2) {
                    return "女"
                } else {
                    return "未知"
                }
            }
        },
        {title: '年龄', field: 'customerAge', align: 'center', valign: 'middle', sortable: true},
        {title: '手机号码', field: 'customerPhone', align: 'center', valign: 'middle', sortable: true},
        {title: '微信号', field: 'wechatNumber', align: 'center', valign: 'middle', sortable: true},
        {title: '建档人', field: 'archiving', align: 'center', valign: 'middle', sortable: true},
        // {title: '手机使用人', field: 'phoneSharShip', align: 'center', valign: 'middle', sortable: true},
        {
            title: '操作', field: 'id', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                var userName = $('#userName').val();
                if (row.entryClerk == userName) {
                    if (row.status == '到店') {
                        return "<a href='javascript:;' onclick='Reservations.openReservationsDetails(" + '"' + row.id + '"' + ")'>[客户详情]</a>" +
                            "<a href='javascript:;' onclick='Reservations.setDiagnosisRecord(" + '"' + row.id + '"' + ")'>[看诊记录]</a>" +
                            "<a href='javascript:;' onclick='Reservations.openBileRecord(" + '"' + row.id + '"' + ")'>[开单记录]</a>"
                    } else {
                        if (row.isSupplement == '是') {
                            return "<a href='javascript:;' onclick='Reservations.openReservationsDetails(" + '"' + row.id + '"' + ")'>[客户详情]</a>"
                        } else {
                            return "<a href='javascript:;' onclick='Reservations.openReservationsDetails(" + '"' + row.id + '"' + ")'>[客户详情]</a>" +
                                "<a href='javascript:;' onclick='Reservations.openReservationsUpdate(" + '"' + row.id + '"' + ")'>[修改]</a>"
                        }
                    }
                } else if (row.archiving == userName || row.follower == userName) {
                    if (row.status == '到店') {
                        return "<a href='javascript:;' onclick='Reservations.openReservationsDetails(" + '"' + row.id + '"' + ")'>[客户详情]</a>" +
                            "<a href='javascript:;' onclick='Reservations.setDiagnosisRecord(" + '"' + row.id + '"' + ")'>[看诊记录]</a>" +
                            "<a href='javascript:;' onclick='Reservations.openBileRecord(" + '"' + row.id + '"' + ")'>[开单记录]</a>"
                    } else {
                        return "<a href='javascript:;' onclick='Reservations.openReservationsDetails(" + '"' + row.id + '"' + ")'>[客户详情]</a>" +
                            "<a href='javascript:;' onclick='Reservations.openReservationsUpdate(" + '"' + row.id + '"' + ")'>[修改]</a>"
                    }
                } else {
                    if (row.status == '到店') {
                        return "<a href='javascript:;' onclick='Reservations.openReservationsDetails(" + '"' + row.id + '"' + ")'>[客户详情]</a>" +
                            "<a href='javascript:;' onclick='Reservations.setDiagnosisRecord(" + '"' + row.id + '"' + ")'>[看诊记录]</a>" +
                            "<a href='javascript:;' onclick='Reservations.openBileRecord(" + '"' + row.id + '"' + ")'>[开单记录]</a>"
                    } else {
                        return "<a href='javascript:;' onclick='Reservations.openReservationsDetails(" + '"' + row.id + '"' + ")'>[客户详情]</a>"
                    }
                }
            }
        },
        {title: '一级渠道', field: 'oneChannel', align: 'center', valign: 'middle', sortable: true},
        {title: '二级渠道', field: 'twoChannel', align: 'center', valign: 'middle', sortable: true},
        {title: '三级渠道', field: 'thrChannel', align: 'center', valign: 'middle', sortable: true},
        {title: '初诊TC', field: 'tcName', align: 'center', valign: 'middle', sortable: true},
        {title: '首次到店', field: 'firstVisitDate', align: 'center', valign: 'middle', sortable: true},
        {
            title: '成交状态', field: 'dealStatus', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                if (value == "已成交") {
                    return "<a href='javascript:;' onclick='Reservations.opendealStatus(" + '"' + row.id + '"' + ")'>[已成交]</a>"
                } else {
                    return value;
                }
            }
        },
        {title: '预约病种', field: 'appointmentPayService', align: 'center', valign: 'middle', sortable: true},
        {title: '访问病种', field: 'accessDisease', align: 'center', valign: 'middle', sortable: true},
        // {title: '录入员', field: 'entryClerk', align: 'center', valign: 'middle', sortable: true},
        {
            title: '建档时间', field: 'filingTime', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                return value.substring(0, 19);
            }
        },
        {title: '是否补单', field: 'isSupplement', align: 'center', valign: 'middle', sortable: true},
    ]
    return columns;
};

Reservations.suspensionOut = function () {
    $('#suspension_box').remove();
};

Reservations.openBileRecord = function (id) {
    var index = layer.open({
        type: 2,
        title: '成交记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_openBileListss/' + id
    });
    this.layerIndex = index;
};

Reservations.suspensionOver = function (id) {
    var str = "";
    var evt = evt || window.event;
    $('#suspension_box').remove();
    var oDiv = document.createElement('div');
    $.ajax({
        url: Feng.ctxPath + "/reservations/getHuiFang",
        type: "post",
        data: {
            "id": id
        },
        success: function (data) {
            if (data) {
                var data_sp = data.substring(1, data.length - 1);
                var arr = data_sp.split('\\n');
                arr.forEach(function (v) {
                    str += "<p>" + v + "</p>"
                });
            } else {
                str = '';
            }
            oDiv.id = 'suspension_box';
            oDiv.innerHTML = str;
            var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
            var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
            var x = evt.pageX || evt.clientX + scrollX;
            var y = evt.pageY || evt.clientY + scrollY;

            oDiv.style.left = x + 0 + 'px';  // 指定创建的DIV在文档中距离左侧的位置
            oDiv.style.top = y + 20 + 'px';  // 指定创建的DIV在文档中距离顶部的位置
            oDiv.style.position = 'absolute'; // 为新创建的DIV指定绝对定位
            oDiv.style.padding = "10px";
            oDiv.style.fontSize = "16px";
            oDiv.style.backgroundColor = ' #75B4ED';
            oDiv.style.color = 'white';
            document.body.appendChild(oDiv);
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
};


/**
 * 检查是否选中
 */
Reservations.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Reservations.seItem = selected[0];
        return true;
    }
};

Reservations.setDiagnosisRecord = function (id) {
    var index = layer.open({
        type: 2,
        title: '看诊记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/diagnosis_detail/' + id
    });
    this.layerIndex = index;
};

Reservations.uploadCustomer = function () {
    var index = layer.open({
        type: 2,
        title: '批量上传',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/customer_import/'
    });
    this.layerIndex = index;
};


Reservations.openRevisit = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '预约回访详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/openRevisit/' + reservationsId
    });
    this.layerIndex = index;
};

Reservations.openNoRevisit = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '不回访原因',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/openNoRevisit/' + reservationsId
    });
    this.layerIndex = index;
};

/*建档，跟进点击*/
Reservations.getArchiving = function () {
    var index = layer.open({
        type: 2,
        title: '选中建档人',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/to_archiving'
    });
    this.layerIndex = index;
};

Reservations.openRevisitRecord = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '回访记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/to_revisitRecord/' + reservationsId
    });
    this.layerIndex = index;
};

Reservations.revisitOperation = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '回访操作',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/to_revisitOperation/' + reservationsId
    });
    this.layerIndex = index;
};

Reservations.revisitOperations = function (id) {
};

Reservations.openAddVisited = function (reservationsId) {
    var index = layer.open({
        type: 2,
        title: '添加回访记录',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/to_addVisited/' + reservationsId
    });
    this.layerIndex = index;
};

/**
 * 点击预约客户
 */
Reservations.openAddReservations = function () {
    var index = layer.open({
        type: 2,
        title: '添加预约客户',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/reservations_add'
    });
    this.layerIndex = index;
};

Reservations.opendealStatus = function (id) {
    $.ajax({
        url: Feng.ctxPath + "/reservations/getTotleMoney",
        type: "post",
        data: {
            "id": id
        },
        success: function (data) {
            alert("成交金额：" + data + "元");
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
};


/**
 * 点击补单预约客户
 */
// Reservations.supplement = function () {
//     var index = layer.open({
//         type: 2,
//         title: '添加预约客户补单',
//         area: ['1500px', '700px'], //宽高
//         fix: true, //不固定
//         maxmin: true,
//         content: Feng.ctxPath + '/reservations/reservations_supplement'
//     });
//     this.layerIndex = index;
// };

Reservations.supplement = function () {
    var customerPhone = $('#customerPhone').val();
    if (customerPhone == null || customerPhone == "") {
        alert("请输入电话号码！");
        return;
    }
    var index = layer.open({
        type: 2,
        title: '到店客户电话补单',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/reservations_supplement/' + customerPhone
    });
    this.layerIndex = index;
};

Reservations.AdministratorsUpdate = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '管理员修改',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/reservations/reservations_AdministratorsUpdate/' + Reservations.seItem.id
        });
        this.layerIndex = index;
    }
};

Reservations.internetAdministratorsUpdate = function () {
    if (this.check()) {
        if (Reservations.seItem.oneChannel == "地推") {
            alert("网电管理员无法修改地推录入数据");
            return;
        }
        if (Reservations.seItem.oneChannel == "直接上门") {
            alert("网电管理员无法修改直接上门录入数据");
            return;
        }
        if (Reservations.seItem.oneChannel == "老带新") {
            alert("网电管理员无法修改老带新录入数据");
            return;
        }
        var index = layer.open({
            type: 2,
            title: '管理员修改',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/reservations/to_internetAdministratorsUpdate/' + Reservations.seItem.id
        });
        this.layerIndex = index;
    }
};

Reservations.openReservationsUpdate = function (id) {
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/reservations_update/' + id
    });
    this.layerIndex = index;
};

Reservations.openReservationsDetails = function (id) {
    var index = layer.open({
        type: 2,
        title: '预约客户详情',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/reservations/reservations_details/' + id
    });
    this.layerIndex = index;
};

Reservations.delete = function (id) {
    if (this.check()) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/reservations/delete/" + Reservations.seItem.id, function (data) {
                Feng.success("删除成功!");
                Reservations.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            // ajax.set("id", Reservations.seItem.id);
            ajax.start();
        };
        Feng.confirm("确认删除 " + Reservations.seItem.title + "?", operation);
    }
};

Reservations.addChatRecord = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '添加咨询内容',
            area: ['90%', '90%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/reservations/to_addChatRecord/' + Reservations.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 查询预约客户列表
 */
Reservations.search = function () {
    Reservations.table.refresh({query: Reservations.formParams()});
    Reservations.table.refresh({query: Reservations.formParams()});

    //查询开单总额
    /**$.ajax({
        type: "GET",
        url: Feng.ctxPath + '/reservations/sumAccount',
        data: Reservations.formParams(),
        dataType: "json",
        success: function (data) {
            $('#aaa').html(data.borrowAmount_sum1);
        }
    });
     //查询退款总额
     $.ajax({
        type: "GET",
        url: Feng.ctxPath + '/reservations/sumAccountTui',
        data: Reservations.formParams(),
        dataType: "json",
        success: function (data) {
            $('#bbb').html(data.borrowAmount_sum2);
        }
    });

     //查询实际
     $.ajax({
        type: "GET",
        url: Feng.ctxPath + '/reservations/account',
        data: Reservations.formParams(),
        dataType: "json",
        success: function (data) {
             $('#ccc').html(data.borrowAmount_sum3);
        }
    });*/

    //查询今日预约人数（点击人数，在表格中显示今日预约的数据，这里可以将 onclick="Reservations.todaySupplement()功能按钮 设置在人数上面 ）
    /** $.ajax({
        type: "GET",
        url: Feng.ctxPath + '/reservations/todayReservations',
        data: Reservations.formParams(),
        dataType: "json",
        success: function (data) {
            $('#ddd').html(data.borrowAmount_sum4);
        }
    });*/


};

Reservations.todaySearch = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#status").val("");
    $("#statuss").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#startAppointmentArrivalTime").val("");
    $("#endAppointmentArrivalTime").val("");
    $("#reservationsNum").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#archiving").val("");
    $("#accessDisease").val("");
    $("#startFilingTime").val("");
    $("#endFilingTime").val("");
    $("#appointmentPayService").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    $("#outpatientName").val("");
    $("#wechatNumber").val("");
    $("#tcName").val("");
    $("#isReturnVisit").val("");
    $("#department").val("");
    document.getElementById("startFilingTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endFilingTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    Reservations.search();
};

Reservations.resetSearch = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#status").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#startAppointmentArrivalTime").val("");
    $("#endAppointmentArrivalTime").val("");
    $("#reservationsNum").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#archiving").val("");
    $("#accessDisease").val("");
    $("#statuss").val("");
    $("#startFilingTime").val("");
    $("#tcName").val("");
    $("#endFilingTime").val("");
    $("#appointmentPayService").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    $("#outpatientName").val("");
    $("#wechatNumber").val("");
    $("#department").val("");
    $("#isReturnVisit").val("");
    Reservations.search();
};


Reservations.todaySupplement = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#status").val("");
    $("#startArrivalTime").val("");
    $("#statuss").val("");
    $("#endArrivalTime").val("");
    $("#reservationsNum").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#startAppointmentArrivalTime").val("");
    $("#endAppointmentArrivalTime").val("");
    $("#archiving").val("");
    $("#accessDisease").val("");
    $("#tcName").val("");
    $("#startFilingTime").val("");
    $("#endFilingTime").val("");
    $("#appointmentPayService").val("");
    $("#outpatientName").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    $("#wechatNumber").val("");
    $("#isReturnVisit").val("");
    $("#department").val("");
    document.getElementById("startRevisitTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endRevisitTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    Reservations.search();
};


Reservations.monthReservations = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#status").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservationsNum").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#startAppointmentArrivalTime").val("");
    $("#endAppointmentArrivalTime").val("");
    $("#statuss").val("");
    $("#archiving").val("");
    $("#tcName").val("");
    $("#accessDisease").val("");
    $("#startFilingTime").val("");
    $("#endFilingTime").val("");
    $("#appointmentPayService").val("");
    $("#outpatientName").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    $("#wechatNumber").val("");
    $("#isReturnVisit").val("");
    $("#department").val("");
    var myDates = new Date();
    myDates.setDate(myDates.getDate() - 7);
    var months;
    var days;
    if ((myDates.getMonth() + 1) < 10) {
        months = "0" + (myDates.getMonth() + 1);
    } else {
        months = "" + (myDates.getMonth() + 1);
    }
    if (myDates.getDate() < 10) {
        days = "0" + myDates.getDate();
    } else {
        days = "" + myDates.getDate();
    }
    var myDatess = new Date();
    myDatess.setDate(myDatess.getDate());
    var monthss;
    var dayss;
    if ((myDatess.getMonth() + 1) < 10) {
        monthss = "0" + (myDatess.getMonth() + 1);
    } else {
        monthss = "" + (myDatess.getMonth() + 1);
    }
    if (myDatess.getDate() < 10) {
        dayss = "0" + myDatess.getDate();
    } else {
        dayss = "" + myDatess.getDate();
    }
    var totalDay = (new Date(myDate.getFullYear(), parseInt(myDate.getMonth() + 1), 0)).getDate();
    console.log(totalDay);
    document.getElementById("startFilingTime").value = myDates.getFullYear() + "-" + months + "-" + "01 00:00:00";
    document.getElementById("endFilingTime").value = myDatess.getFullYear() + "-" + monthss + "-" + totalDay + " " + "23:59:59";
    Reservations.search();
};

Reservations.yesterdayReservations = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#status").val("");
    $("#tcName").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#startAppointmentArrivalTime").val("");
    $("#endAppointmentArrivalTime").val("");
    $("#reservationsNum").val("");
    $("#startRevisitTime").val("");
    $("#statuss").val("");
    $("#endRevisitTime").val("");
    $("#archiving").val("");
    $("#accessDisease").val("");
    $("#startFilingTime").val("");
    $("#endFilingTime").val("");
    $("#appointmentPayService").val("");
    $("#outpatientName").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    $("#wechatNumber").val("");
    $("#isReturnVisit").val("");
    $("#department").val("");
    var myDates = new Date();
    myDates.setDate(myDates.getDate() - 1);
    var months;
    var days;
    if ((myDates.getMonth() + 1) < 10) {
        months = "0" + (myDates.getMonth() + 1);
    } else {
        months = "" + (myDates.getMonth() + 1);
    }
    if (myDates.getDate() < 10) {
        days = "0" + myDates.getDate();
    } else {
        days = "" + myDates.getDate();
    }
    document.getElementById("startFilingTime").value = myDates.getFullYear() + "-" + months + "-" + days + " " + "00:00:00";
    document.getElementById("endFilingTime").value = myDates.getFullYear() + "-" + months + "-" + days + " " + "23:59:59";
    Reservations.search();
};


Reservations.monthdayArrive = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#status").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#tcName").val("");
    $("#startAppointmentArrivalTime").val("");
    $("#endAppointmentArrivalTime").val("");
    $("#reservationsNum").val("");
    $("#startRevisitTime").val("");
    $("#statuss").val("");
    $("#endRevisitTime").val("");
    $("#archiving").val("");
    $("#accessDisease").val("");
    $("#startFilingTime").val("");
    $("#endFilingTime").val("");
    $("#appointmentPayService").val("");
    $("#outpatientName").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    $("#wechatNumber").val("");
    $("#isReturnVisit").val("");
    $("#department").val("");
    var myDates = new Date();
    myDates.setDate(myDates.getDate() - 7);
    var months;
    var days;
    if ((myDates.getMonth() + 1) < 10) {
        months = "0" + (myDates.getMonth() + 1);
    } else {
        months = "" + (myDates.getMonth() + 1);
    }
    if (myDates.getDate() < 10) {
        days = "0" + myDates.getDate();
    } else {
        days = "" + myDates.getDate();
    }
    var myDatess = new Date();
    myDatess.setDate(myDatess.getDate());
    var monthss;
    var dayss;
    if ((myDatess.getMonth() + 1) < 10) {
        monthss = "0" + (myDatess.getMonth() + 1);
    } else {
        monthss = "" + (myDatess.getMonth() + 1);
    }
    if (myDatess.getDate() < 10) {
        dayss = "0" + myDatess.getDate();
    } else {
        dayss = "" + myDatess.getDate();
    }
    var totalDay = (new Date(myDate.getFullYear(), parseInt(myDate.getMonth() + 1), 0)).getDate();
    document.getElementById("startArrivalTime").value = myDates.getFullYear() + "-" + months + "-" + "01 00:00:00";
    document.getElementById("endArrivalTime").value = myDates.getFullYear() + "-" + monthss + "-" + totalDay + " " + "23:59:59";
    Reservations.search();
};

Reservations.yesterdayArrive = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#status").val("");
    $("#startArrivalTime").val("");
    $("#statuss").val("");
    $("#endArrivalTime").val("");
    $("#startAppointmentArrivalTime").val("");
    $("#endAppointmentArrivalTime").val("");
    $("#reservationsNum").val("");
    $("#startRevisitTime").val("");
    $("#tcName").val("");
    $("#endRevisitTime").val("");
    $("#archiving").val("");
    $("#accessDisease").val("");
    $("#startFilingTime").val("");
    $("#endFilingTime").val("");
    $("#appointmentPayService").val("");
    $("#outpatientName").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    $("#wechatNumber").val("");
    $("#isReturnVisit").val("");
    $("#department").val("");
    var myDates = new Date();
    myDates.setDate(myDates.getDate() - 1);
    var months;
    var days;
    if ((myDates.getMonth() + 1) < 10) {
        months = "0" + (myDates.getMonth() + 1);
    } else {
        months = "" + (myDates.getMonth() + 1);
    }
    if (myDates.getDate() < 10) {
        days = "0" + myDates.getDate();
    } else {
        days = "" + myDates.getDate();
    }
    document.getElementById("startArrivalTime").value = myDates.getFullYear() + "-" + months + "-" + days + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDates.getFullYear() + "-" + months + "-" + days + " " + "23:59:59";
    Reservations.search();
};

Reservations.todayArrive = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#status").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#reservationsNum").val("");
    $("#tcName").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#startAppointmentArrivalTime").val("");
    $("#endAppointmentArrivalTime").val("");
    $("#statuss").val("");
    $("#archiving").val("");
    $("#accessDisease").val("");
    $("#startFilingTime").val("");
    $("#endFilingTime").val("");
    $("#appointmentPayService").val("");
    $("#outpatientName").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    $("#wechatNumber").val("");
    $("#isReturnVisit").val("");
    $("#department").val("");
    var myDates = new Date();
    myDates.setDate(myDates.getDate());
    var months;
    var days;
    if ((myDates.getMonth() + 1) < 10) {
        months = "0" + (myDates.getMonth() + 1);
    } else {
        months = "" + (myDates.getMonth() + 1);
    }
    if (myDates.getDate() < 10) {
        days = "0" + myDates.getDate();
    } else {
        days = "" + myDates.getDate();
    }
    document.getElementById("startArrivalTime").value = myDates.getFullYear() + "-" + months + "-" + days + " " + "00:00:00";
    document.getElementById("endArrivalTime").value = myDates.getFullYear() + "-" + months + "-" + days + " " + "23:59:59";
    Reservations.search();
};

var parseParam = function (param, key) {
    var paramStr = "";
    if (param instanceof String || param instanceof Number || param instanceof Boolean) {
        paramStr += "&" + key + "=" + param;
    } else {
        $.each(param, function (i) {
            var k = key == null ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i);
            paramStr += '&' + parseParam(this, k);
        });
    }
    return paramStr.substr(1);
};

Reservations.tomorrowSupplement = function () {
    $("#customerName").val("");
    $("#customerPhone").val("");
    $("#status").val("");
    $("#startArrivalTime").val("");
    $("#endArrivalTime").val("");
    $("#startAppointmentArrivalTime").val("");
    $("#endAppointmentArrivalTime").val("");
    $("#reservationsNum").val("");
    $("#startRevisitTime").val("");
    $("#endRevisitTime").val("");
    $("#statuss").val("");
    $("#tcName").val("");
    $("#archiving").val("");
    $("#accessDisease").val("");
    $("#startFilingTime").val("");
    $("#endFilingTime").val("");
    $("#appointmentPayService").val("");
    $("#outpatientName").val("");
    $("#oneChannel").val("");
    $("#twoChannel").val("");
    $("#thrChannel").val("");
    $("#wechatNumber").val("");
    $("#isReturnVisit").val("");
    $("#department").val("");
    var myDates = new Date();
    myDates.setDate(myDates.getDate() + 1);
    var months;
    var days;
    if ((myDates.getMonth() + 1) < 10) {
        months = "0" + (myDates.getMonth() + 1);
    } else {
        months = "" + (myDates.getMonth() + 1);
    }
    if (myDates.getDate() < 10) {
        days = "0" + myDates.getDate();
    } else {
        days = "" + myDates.getDate();
    }
    document.getElementById("startRevisitTime").value = myDates.getFullYear() + "-" + months + "-" + days + " " + "00:00:00";
    document.getElementById("endRevisitTime").value = myDates.getFullYear() + "-" + months + "-" + days + " " + "23:59:59";
    Reservations.search();
};


/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Reservations.formParams = function () {
    var queryData = {};
    queryData['customerName'] = $("#customerName").val().trim();
    queryData['customerPhone'] = $("#customerPhone").val();
    queryData['status'] = $("#status").val();
    queryData['appointmentPayService'] = $("#appointmentPayService").val();
    queryData['startRevisitTime'] = $("#startRevisitTime").val();
    queryData['endRevisitTime'] = $("#endRevisitTime").val();
    queryData['archiving'] = $("#archiving").val();
    queryData['accessDisease'] = $("#accessDisease").val();
    queryData['startFilingTime'] = $("#startFilingTime").val();
    queryData['endFilingTime'] = $("#endFilingTime").val();
    queryData['outpatientName'] = $("#outpatientName").val();
    queryData['startArrivalTime'] = $("#startArrivalTime").val();
    queryData['endArrivalTime'] = $("#endArrivalTime").val();
    queryData['oneChannel'] = $("#oneChannel").val();
    queryData['twoChannel'] = $("#twoChannel").val();
    queryData['thrChannel'] = $("#thrChannel").val();
    queryData['reservationsNum'] = $("#reservationsNum").val();
    queryData['wechatNumber'] = $("#wechatNumber").val();
    queryData['isReturnVisit'] = $("#isReturnVisit").val();
    queryData['statuss'] = $("#statuss").val();
    queryData['department'] = $("#department").val();
    queryData['startAppointmentArrivalTime'] = $("#startAppointmentArrivalTime").val();
    queryData['endAppointmentArrivalTime'] = $("#endAppointmentArrivalTime").val();
    queryData['tcName'] = $("#tcName").val();
    return queryData;
}

Reservations.reservationsExport = function () {
    var queryData = {};
    queryData['customerName'] = $("#customerName").val().trim();
    queryData['customerPhone'] = $("#customerPhone").val();
    queryData['status'] = $("#status").val();
    queryData['appointmentPayService'] = $("#appointmentPayService").val();
    queryData['startRevisitTime'] = $("#startRevisitTime").val();
    queryData['endRevisitTime'] = $("#endRevisitTime").val();
    queryData['archiving'] = $("#archiving").val();
    queryData['accessDisease'] = $("#accessDisease").val();
    queryData['startFilingTime'] = $("#startFilingTime").val();
    queryData['endFilingTime'] = $("#endFilingTime").val();
    queryData['outpatientName'] = $("#outpatientName").val();
    queryData['startArrivalTime'] = $("#startArrivalTime").val();
    queryData['endArrivalTime'] = $("#endArrivalTime").val();
    queryData['oneChannel'] = $("#oneChannel").val();
    queryData['twoChannel'] = $("#twoChannel").val();
    queryData['thrChannel'] = $("#thrChannel").val();
    queryData['reservationsNum'] = $("#reservationsNum").val();
    queryData['wechatNumber'] = $("#wechatNumber").val();
    queryData['isReturnVisit'] = $("#isReturnVisit").val();
    queryData['statuss'] = $("#statuss").val();
    queryData['tcName'] = $("#tcName").val();
    queryData['department'] = $("#department").val();
    queryData['startAppointmentArrivalTime'] = $("#startAppointmentArrivalTime").val();
    queryData['endAppointmentArrivalTime'] = $("#endAppointmentArrivalTime").val();
    var param = parseParam(queryData);
    location.href = Feng.ctxPath + '/reservations/reservationsExport?' + param;
}

var myDate = new Date();
var month;
var day;
if ((myDate.getMonth() + 1) < 10) {
    month = "0" + (myDate.getMonth() + 1);
} else {
    month = "" + (myDate.getMonth() + 1);
}
if (myDate.getDate() < 10) {
    day = "0" + myDate.getDate();
} else {
    day = "" + myDate.getDate();
}
$(function () {
    $.post(Feng.ctxPath + "/payService/getList", function (data) {
        var txt = '<option value="">--请选择预约项目--</option>';
        for (var i = 0; i < data.length; i++) {
            txt += '<option value="' + data[i].department + '">' + data[i].department + '</option>';
        }
        document.getElementById('appointmentPayService').innerHTML = txt;
        //状态单选
        var seletepayservicename = $('#payservicenameValue').val();
        if (seletepayservicename != "") {
            $("#appointmentPayService option[value=" + seletepayservicename + "]").attr("selected", "selected");
        }
    }, "json");

    document.getElementById("endFilingTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    var defaultColunms = Reservations.initColumn();
    var table = new BSTable(Reservations.id, "/reservations/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(Reservations.formParams());
    Reservations.table = table.init();
    Reservations.search();
    //初始化下拉到店门诊列表
    $.post(Feng.ctxPath + "/payService/getList", function (data) {
        var txt = '<option value="">--请选择预约项目--</option>';
        for (var i = 0; i < data.length; i++) {
            txt += '<option value="' + data[i].department + '">' + data[i].department + '</option>';
        }
        document.getElementById('appointmentPayService').innerHTML = txt;
        //状态单选
        var seletepayservicename = $('#payservicenameValue').val();
        if (seletepayservicename != "") {
            $("#appointmentPayService option[value=" + seletepayservicename + "]").attr("selected", "selected");
        }
    }, "json");

    //初始化下拉到店门诊列表
    $.post(Feng.ctxPath + "/outpatientManagement/getList", function (data) {
        var txt = '<option value="">--请选择到店门诊--</option>';
        console.log(data);
        for (var i = 0; i < data.length; i++) {
            txt += '<option value="' + data[i].simplename + '">' + data[i].simplename + '</option>';
        }
        document.getElementById('outpatientName').innerHTML = txt;
        //状态单选
        var seleteooutpatientName = $('#outpatientNameValue').val();
        if (seleteooutpatientName != "") {
            $("#outpatientName option[value=" + seleteooutpatientName + "]").attr("selected", "selected");
        }
    }, "json");

    //今日界面后，第一次调用统计
});
